package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ8A implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle8A01(cmd);
            case 0x10:
                return handle8A10(cmd);
            case 0x11:
                return handle8A11(cmd);
            case 0x12:
                return handle8A12(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8A12(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:查询平台下发到终端照片指令");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"司机电子证件照");
        list.put(1,"人脸识别");
        list.put(2,"其他");
        builder.append("下载用途:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8A11(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:照片删除");
        builder.append("\r\n");

        int num = cmd.readInt();
        builder.append("照片数量:"+num);
        builder.append("\r\n");
        for (int i = 0; i < num; i++) {
            builder.append("    照片ID:"+cmd.readInt(4));
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle8A10(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:照片下发");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"司机电子证件照");
        list.put(1,"人脸识别");
        list.put(2,"其他");
        builder.append("下载用途:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("照片ID:"+cmd.readInt(4));
        builder.append("\r\n");

        builder.append("准许证号:"+cmd.readString(19));
        builder.append("\r\n");

        builder.append("司机姓名:"+cmd.readString(-1));
        builder.append("\r\n");

        builder.append("司机代码:"+cmd.readString(-1));
        builder.append("\r\n");

        builder.append("照片数据大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("起始地址:"+cmd.readInt(4));
        builder.append("\r\n");

        builder.append("照片数据:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8A01(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:下发司机信息");
        builder.append("\r\n");

        builder.append("单位名称："+cmd.readString(-1));
        builder.append("\r\n");
        builder.append("企业经营许可证号："+cmd.readString(16));
        builder.append("\r\n");
        builder.append("公司联系电话："+cmd.readString(11));
        builder.append("\r\n");
        builder.append("政府监管电话："+cmd.readString(11));
        builder.append("\r\n");
        builder.append("姓名："+cmd.readString(-1));
        builder.append("\r\n");
        builder.append("身份证号："+cmd.readString(19));
        builder.append("\r\n");
        builder.append("登记日期："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("有效日期："+cmd.readBCD(3));
        builder.append("\r\n");
        builder.append("车牌号："+cmd.readString(-1));
        builder.append("\r\n");
        builder.append("准许证号："+cmd.readString(11));
        builder.append("\r\n");
        builder.append("驾驶员星数："+cmd.readInt(1));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"主班");
        list.put(1,"副班");
        list.put(2,"机动");
        builder.append("司机类型："+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");


        return builder.toString();
    }
}
